package com.excel.easyExcel.result;

import com.excel.easyExcel.result.Impl.ResultCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author Xinjie
 * @date 2023/1/2 14:59
 */
@Data
public class ResultVo<T> implements Serializable {
    private int code;

    private String msg;

    private T data;

    public ResultVo(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 默认返回成功状态码
     * @param data 返回的数据
     */
    public ResultVo(T data) {
        this.code = ResultCode.SUCCESS.getCode();
        this.msg = ResultCode.SUCCESS.getMsg();
        this.data = data;
    }

    /**
     * 返回指定状态码，数据对象
     * @param statusCode 状态码
     * @param data 返回的数据
     */
    public ResultVo(StatusCode statusCode,T data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

    /**
     * 只返回状态码，一般用于错误时
     * @param statusCode 状态码
     */
    public ResultVo(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = null;
    }
}
